######标准化——————————————————————————————————————————————————————————————————————————————————————————————————
###（1)在Pandas 中实现[Z-Score]
# Importing the library
import pandas as pd

# # Creating the data frame
# details = {
#     'col1': [1, 3, 5, 7, 9],
#     'col2': [7, 4, 35, 14, 56]
# }
#
# # creating a Dataframe object
# df = pd.DataFrame(details)
#
# # Z-Score using pandas
# df['col1'] = (df['col1'] - df['col1'].mean()) / df['col1'].std()
# # 输出处理后的数据
# print("Z-Score 标准化后的数据:")
# print(df)
#
# # 输出统计信息
# print("\n统计信息:")
# print(f"col1 的均值: {df['col1'].mean():.4f}")
# print(f"col1 的标准差: {df['col1'].std():.4f}")





###（2)使用 scipy.stats()
# Importing the library

# import pandas as pd
# import scipy
# from scipy import stats
#
# # Creating the data frame
# details = {
#     'col1': [1, 3, 5, 7, 9],
#     'col2': [7, 4, 35, 14, 56]
# }
#
# # creating a Dataframe object
# df = pd.DataFrame(details)
#
# # Z-Score using scipy
# df['col2'] = stats.zscore(df['col2'])
#
# # 输出处理后的数据
# print("Z-Score 标准化后的数据:")
# print(df)
#
# # 输出统计信息
# print("\n统计信息:")
# print(f"col1 的均值: {df['col1'].mean():.4f}")
# print(f"col1 的标准差: {df['col1'].std():.4f}")




###(3)使用 sci-kit learn 标准扩展器
# # Importing the library
# import pandas as pd
# from sklearn.preprocessing import StandardScaler
# import numpy as np
#
#
# # Creating the data frame
# details = {
#     'col1': [1, 3, 5, 7, 9],
#     'col2': [7, 4, 35, 14, 56]
# }
#
# # creating a Dataframe object
# df = pd.DataFrame(details)
#
# # define standard scaler
# scaler = StandardScaler()
#
# # transform data
# scaled_df = scaler.fit_transform(df)
# # 输出处理后的数据
# print("Z-Score 标准化后的数据:")
# print(scaled_df)
#
# # 输出统计信息
# print("\n统计信息:")
# # 直接使用numpy数组的统计方法
# print(f"第一列的均值: {np.mean(scaled_df[:, 0]):.4f}")
# print(f"第一列的标准差: {np.std(scaled_df[:, 0]):.4f}")




######离散化——————————————————————————————————————————————————————————————————————————————————
##（1）等频分箱
# import pandas as pd
#
# # 创建示例数据
# data = pd.Series([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
#
# # 设置自定义箱子边界
# bins = [-0.1, 2, 4, 6, 8.1]
#
# # 使用cut函数进行自定义分箱
# result = pd.cut(data, bins)
# print(result)




# #(2）等宽分箱
# import pandas as pd
#
# # 创建示例数据
# data = pd.Series([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
#
# # 使用cut函数进行等宽分箱
# bins = pd.cut(data, 5, retbins=True)
#
# print(bins)



##（3）自定义分箱
import pandas as pd

# 创建示例数据
data = pd.Series([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])

# 设置自定义箱子边界
bins = [-0.1, 2, 4, 6, 8.1]

# 使用cut函数进行自定义分箱
result = pd.cut(data, bins)

print(result)